from django.db import models
from users.models import UserInfo


class LoanNote(models.Model):
    """借条"""
    CATES = (
        (0, '出借人'),
        (1, '借款人'),
        (2, '保证人'),
    )
    cate = models.IntegerField(verbose_name="身份属性", blank=True, null=True, choices=CATES)
    # 出借人
    lender_name = models.CharField(verbose_name="出借人姓名", max_length=32, blank=True, null=True)
    lender_ident = models.CharField(verbose_name="出借人身份证", max_length=24, blank=True, null=True)
    #  借款人
    borrower_name = models.CharField(verbose_name="借款人姓名", max_length=32, blank=True, null=True)
    borrower_ident = models.CharField(verbose_name="借款人身份证", max_length=24, blank=True, null=True)
    co_borrower_name = models.CharField(verbose_name="共同借款人姓名", max_length=32, blank=True, null=True)
    co_borrower_ident = models.CharField(verbose_name="共同出借人身份证", max_length=24, blank=True, null=True)
    borrower_address = models.CharField(verbose_name="借款人家庭地址", max_length=128, blank=True, null=True)
    borrower_phone = models.CharField(verbose_name="借款人手机", max_length=32, blank=True, null=True)
    borrower_wechat = models.CharField(verbose_name="借款人微信", max_length=32, blank=True, null=True)
    borrower_unit_address = models.CharField(verbose_name="借款人单位地址", max_length=128, blank=True, null=True)
    borrower_unit_phone = models.CharField(verbose_name="借款人单位电话", max_length=24, blank=True, null=True)
    # 保证人
    guarantor_name = models.CharField(verbose_name="保证人姓名", max_length=32, blank=True, null=True)
    guarantor_ident = models.CharField(verbose_name="保证人身份证", max_length=32, blank=True, null=True)
    guarantor_address = models.CharField(verbose_name="保证人家庭地址", max_length=128, blank=True, null=True)
    guarantor_phone = models.CharField(verbose_name="保证人手机", max_length=32, blank=True, null=True)
    guarantor_wechat = models.CharField(verbose_name="保证人微信", max_length=32, blank=True, null=True)
    guarantor_unit_address = models.CharField(verbose_name="保证人单位地址", max_length=128, blank=True, null=True)
    guarantor_unit_phone = models.CharField(verbose_name="保证人单位电话", max_length=24, blank=True, null=True)
    loan_usage = models.CharField(verbose_name="借款用途", max_length=64, blank=True, null=True)
    loan_money = models.FloatField(verbose_name="借款金额小写", blank=True, null=True)
    loan_word_money = models.CharField(verbose_name="借款金额大写", max_length=64, blank=True, null=True)
    loan_term = models.IntegerField(verbose_name="借款期限", blank=True, null=True)
    loan_begin_date = models.DateField(verbose_name="开始日期", blank=True, null=True)
    loan_end_date = models.DateField(verbose_name="截止日期", blank=True, null=True)
    repay_account_name = models.CharField(verbose_name="还款账户名称", max_length=64, blank=True, null=True)
    repay_account = models.CharField(verbose_name="还款账户", max_length=64, blank=True, null=True)
    repay_bank = models.CharField(verbose_name="还款开户银行", max_length=64, blank=True, null=True)
    interest_unit_time = models.CharField(verbose_name="计息单位时间", max_length=12, blank=True, null=True)
    interest = models.FloatField(verbose_name="利息", blank=True, null=True)
    interest_settle_time = models.DateField(verbose_name="利息结算时间", blank=True, null=True)
    date_penalty = models.CharField(verbose_name="日违约金", max_length=32, blank=True, null=True)
    collateral = models.CharField(verbose_name="抵押物", max_length=32, blank=True, null=True)
    user = models.ForeignKey(UserInfo, verbose_name="录入人", blank=True, null=True, on_delete=models.SET_NULL, db_constraint=False)
    update_time = models.DateTimeField(verbose_name="修改时间", auto_now=True)
    add_time = models.DateTimeField(verbose_name="增加时间", auto_now_add=True)

    def __str__(self):
        return self.lender_name

    class Meta:
        verbose_name = "借条"
        verbose_name_plural = verbose_name
        ordering = ["-id"]





